package sv.ues.fia.adminperfildocentes;

import java.util.ArrayList;

import sv.ues.fia.adminperfildocentes.adapter.GridviewAdapter;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;

public class DocenteActivity extends Activity {
	
	private GridviewAdapter mAdapter;
	private ArrayList<String> listTitulo;
	private ArrayList<Integer> listCatalogo;
	private ArrayList<String> listClass;
	private GridView gridView;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_docente);
		
		prepareList();
        
        // prepared arraylist and passed it to the Adapter class
        mAdapter = new GridviewAdapter(this,listTitulo, listCatalogo);
        
        // Set custom adapter to gridview
        gridView = (GridView) findViewById(R.id.gridView2);
        gridView.setAdapter(mAdapter);
        
        // Implement On Item click listener
        gridView.setOnItemClickListener(new OnItemClickListener() 
        {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int position,
					long arg3) {
							
				try{
					String nombreValue=listClass.get(position);
	    			Class<?> clase=Class.forName("sv.ues.fia.adminperfildocentes."+nombreValue);
	    			 Intent inte = new Intent(getApplicationContext(), clase);
	    			startActivity(inte);
	    		}catch(ClassNotFoundException e){
	    			e.printStackTrace();
	    			Toast.makeText(DocenteActivity.this,getResources().getString(R.string.class_no_encontrada), Toast.LENGTH_SHORT).show();
	    		}
	    		
			}
		});
	}

	public void prepareList()
    {
    	  listTitulo = new ArrayList<String>();
    	  listTitulo.add(getResources().getString(R.string.miperfil_icon));
    	  
          listCatalogo = new ArrayList<Integer>();
          listCatalogo.add(R.drawable.professor_icon);
          
          listClass = new ArrayList<String>();
          listClass.add("PerfilDocenteActivity");
    	  
    }

}
